/**
 * @author 徐楠
 * @date 2022/2/3 23:57
 * @version 1.0
 */

package com.xunan.likou;

public class IntegerInversion {

    public static void main(String[] args) {
        int result = reverse(-123);
        //System.out.println(-1 % 10);//-1
        System.out.println(Integer.MIN_VALUE );
        System.out.println(result);
    }

    public static int reverse(int x) {
        int result = 0;
        while (x != 0) {
            if (result < Integer.MIN_VALUE / 10 || result > Integer.MAX_VALUE / 10) {
                return 0;
            }
            int temp = x % 10;
            x /= 10;
            result = result * 10 + temp;
        }
        return result;
    }
}
